package io.github.heollhai.common.utils.tree;

import io.github.heollhai.common.utils.VerifyUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: lmf
 * @Create: 2024/8/9 9:54
 * Description: 实现默认的树节点
 */
public abstract class AbstractTreeNode<T extends AbstractTreeNode<T,V,K>,V,K> implements TreeNode<T,V,K>{

    @Override
    public abstract V getId();

    @Override
    public abstract K getPid();

    public Integer sort;
    public List<T> children = new ArrayList<>();

    @Override
    public Integer getSort() {
        return this.sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    @Override
    public List<T> getChildren() {
        return this.children;
    }

    @Override
    public void setChildren(List<T> children) {
        this.children = children;
    }

    @Override
    public void addChildren(T children) {
        if(VerifyUtils.isEmpty(this.children)){
            this.children = new ArrayList<>();
        }
        this.children.add(children);
    }
}
